package net.minecraft.src;

public abstract class LF_BlockSeat extends LF_BlockFurnitureBase 
{
	public LF_BlockSeat(int a, int b, Class class1, Material mat)
	{
		super(a,b,class1,mat);
	}

	public int[] getSeatXYZ(World world, int x, int y, int z)
	{
		int[] array = {x, y, z};
		return array;
	}

	public float fixRotation(float yaw, int meta)
	{
		float yaw2 = yaw;
		int angleOffset;

		if(meta % 4 == 0)
			angleOffset = -90;
		else if(meta % 4 == 1)
			angleOffset = 90;
		else if(meta % 4 == 2)
			angleOffset = 180;
		else angleOffset = 0;
			yaw2 -= angleOffset;

		while(yaw2 > 360 || yaw2 < 0)
		{
			if(yaw2 < 0)
				yaw2 += 360;
			else if(yaw2 > 360)
				yaw2 -= 360;
		}

		if(yaw2 < getLowerAngleLimit(meta) && yaw2 > getMidAngle(meta))
			yaw2 = getLowerAngleLimit(meta);
		if(yaw2 > getUpperAngleLimit(meta) && yaw2 < getMidAngle(meta))
			yaw2 = getUpperAngleLimit(meta);

		yaw2 += angleOffset;

		return yaw2;
	}

	public float getUpperAngleLimit(int meta) {  return 90F; }
	public float getMidAngle(int meta) { return 180F; }
	public float getLowerAngleLimit(int meta) {  return 270F; }

	@Override
	public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
	{
		if(entityplayer.ridingEntity == null)
		{
			int[] array = new int[3];
			array = getSeatXYZ(world, i, j, k);
			int x = array[0];
			int y = array[1];
			int z = array[2];

			LF_EntitySeatBackup seat = new LF_EntitySeatBackup(world, x, y, z, entityplayer, this);
			seat.firstYaw = entityplayer.rotationYaw;

			world.spawnEntityInWorld(seat);
			entityplayer.mountEntity(seat);
		}
		else if(entityplayer.ridingEntity instanceof LF_EntitySeatBackup)
			entityplayer.mountEntity(null);

		return true;
	}

	public abstract float getSeatHeight();
}
